package com.ruoyi.map.service.impl;

import java.util.List;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.map.domain.ApplyInvestigation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.map.mapper.AdviceFeedbackMapper;
import com.ruoyi.map.domain.AdviceFeedback;
import com.ruoyi.map.service.IAdviceFeedbackService;

/**
 * 用户意见反馈Service业务层处理
 *
 * @author dihang
 * @date 2023-08-14
 */
@Service
public class AdviceFeedbackServiceImpl extends ServiceImpl<AdviceFeedbackMapper, AdviceFeedback> implements IAdviceFeedbackService
{
    @Autowired
    private AdviceFeedbackMapper adviceFeedbackMapper;

    /**
     * 查询用户意见反馈列表
     *
     *
     * @param adviceFeedback 用户意见反馈
     * @return 用户意见反馈
     */

    @Override
    public IPage<AdviceFeedback> selectAdviceFeedbackList(AdviceFeedback adviceFeedback) {
        IPage<AdviceFeedback> page=this.page(new Page<>(adviceFeedback.getPageNum(),
                adviceFeedback.getPageSize()),oneSelectWhere(adviceFeedback));
        return page;
    }


    /**
     * 条件筛选
     * @param adviceFeedback
     * @return
     */
    private LambdaQueryWrapper<AdviceFeedback> oneSelectWhere(AdviceFeedback adviceFeedback) {
        LambdaQueryWrapper<AdviceFeedback>lambdaQueryWrapper=new LambdaQueryWrapper<>();
        if (adviceFeedback==null){
            return lambdaQueryWrapper;
        }
        //姓名筛选
        lambdaQueryWrapper.like(StrUtil.isNotBlank(adviceFeedback.getName()),
                AdviceFeedback::getName,adviceFeedback.getName());
//                .eq(StringUtils.isNotNull(adviceFeedback.getAge()),AdviceFeedback::getAge,adviceFeedback.getAge());
        //反馈类型筛选
        if (adviceFeedback.getFeedbackType()!=null){
            lambdaQueryWrapper.eq(AdviceFeedback::getFeedbackType,adviceFeedback.getFeedbackType());
        }
        //性别筛选
        if (adviceFeedback.getGender()!=null){
            lambdaQueryWrapper.eq(AdviceFeedback::getGender,adviceFeedback.getGender());

        }
                //未删除
                lambdaQueryWrapper.eq(AdviceFeedback::getDeleted,"0");
        //创建时间倒序
        lambdaQueryWrapper.orderByDesc(AdviceFeedback::getCreateTime);
        return lambdaQueryWrapper;
    }

    /**
     * 根据id查询详情
     * @param id
     * @return
     */
    @Override
    public AdviceFeedback selectId(Long id) {
        return adviceFeedbackMapper.selectId(id);
    }

}
